<?php
/**
 * Created by JetBrains PhpStorm.
 * User: T420
 * Date: 11/29/12
 * Time: 10:42 PM
 * To change this template use File | Settings | File Templates.
 */
class Controllers_Menuproduct extends Libs_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->model=new Models_Menuproduct();
    }
    public function index()
    {
        $this->view->listmn=$this->model->getmenuproduct();
        $this->view->render('menuproduct/index');
    }
    public function del($param=null)
    {
        $this->model->delmn($param[0]);
        $this->index();
    }
    public function add()
    {
        $this->view->nhomsp=$this->model->getnhomsp();
        $this->view->render('menuproduct/add');
        if($_REQUEST['themcn'])
        {
            $tencn=$_REQUEST['tencn'];
            $trangthaicn=$_REQUEST['trangthaicn'];
            $nhomsp=$_REQUEST['nhomsp'];
            $check=$this->model->checkpf($tencn);
            if(count($check))
                echo"<script>alert('Tên chức năng này đã tồn tại, mời chọn 1 tên khác!'); onload=function(){frmthemcn.tencn.focus();};</script>";
            else
            {
                $this->model->insertpf($nhomsp,$tencn,$trangthaicn);
                echo"<script>alert('Thêm thành công!');</script>";
            }
        }
    }
    public function update()
    {
        foreach($_POST['status'] as $key=>$value)
        {
            $this->model->updatemenupro($key,$value);
        }
        $this->index();
    }
}
